package com.zhxl.model.test;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;



public class QueryContextServiceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("test test test test test ");
		ServletContext sc = getServletContext();
		WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
		ClassPathXmlApplicationContext context1 = (ClassPathXmlApplicationContext) new ClassPathXmlApplicationContext("applicationContext.xml");
		/**
		 * java.lang.ClassCastException: org.springframework.context.support.ClassPathXmlApplicationContext 
		 * cannot be cast to org.springframework.web.context.WebApplicationContext
		 */
			
		//QueryContextDaoImpl qcc = (QueryContextDaoImpl) su.getObject("queryContextDaoImpl");
		//QueryContextDaoImpl qc = (QueryContextDaoImpl) context.getBean("queryContextDaoImpl");
		//System.out.println(qcc.getContext());
//		String result = qc.QueryContext();
//		System.out.println(result);
	}
}
